<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	template="/WEB-INF/template/template.xhtml">	
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
	<ui:define name="body">
		<script> 
			function limitTextArea(element, limit) { 							
				if (element.value.length > limit) { 
					element.value = element.value.substring(0, limit); 
				} 							
			} 
		</script> 
		<h:form id="formEnquete" acceptcharset="ISO-8859-1">
			<div class="body_center_100">
				<rich:panel>					
					<f:facet name="header">
	        			ENQUETE	        			
	        		</f:facet>
					
					<h:panelGrid columns="2">
						<h:outputLabel value="Questão" />
						<h:inputTextarea style="resize: none;" rows="2" cols="60" value="#{enqueteMB.buscarEnquete.questao}"
						onkeyup="limitTextArea(this,120);" onkeydown="limitTextArea(this,120);" />

						<h:outputLabel value="Status:" />
						<h:selectBooleanCheckbox value="#{enqueteMB.buscarEnquete.status}"></h:selectBooleanCheckbox> 
					</h:panelGrid>
	
					<h:commandButton value="Buscar" action="#{enqueteMB.buscar}"></h:commandButton>
	        		<h:commandButton value="Salvar" action="#{enqueteMB.salvar}"></h:commandButton>
	        		<h:commandButton value="Limpar" action="#{enqueteMB.limpar}"></h:commandButton><br/> <br/>
					
					<rich:dataTable value="#{enqueteMB.enquetes}" var="enquete" rows="9">
						<h:column>
							<f:facet name="header">Questão</f:facet>
							<h:outputText value="#{enquete.questao}"></h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Data de Criação</f:facet>
							<h:outputText value="#{enquete.datacriacao}">
								<f:convertDateTime pattern="dd/MM/yyyy"/>  
							</h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Status</f:facet>
								<h:outputText value="#{enquete.status == true ? 'Ativo' : 'Inativo'}"></h:outputText>													
						</h:column>						
						<h:column>
							<f:facet name="header">Editar</f:facet>
							<h:commandLink action="#{enqueteMB.editar(enquete)}">
								<h:graphicImage library="edit.png" url="/resources/images/edit.png"></h:graphicImage>
							</h:commandLink>
						</h:column>
						<c:if test="#{enqueteMB.status == true}">
							<h:column>
								<f:facet name="header">Encerrar</f:facet>
								<h:commandLink action="#{enqueteMB.encerrar(enquete)}">
									<h:graphicImage library="edit.png" url="/resources/images/delete.png"></h:graphicImage>
								</h:commandLink>
							</h:column>
						</c:if>					
						<f:facet name="footer">  
				        	<rich:dataScroller></rich:dataScroller>  
				      	</f:facet> 
					</rich:dataTable>
				</rich:panel>
			</div>
		</h:form>
	</ui:define>
</ui:composition>